package com.imooc.framework.innerclass;

public class ExampleInnerClass {

    private static String outName = "张三";
    private Integer outAge = 18;

    public static void outerStaticMethod(){
        System.out.println("outerStaticMethod"  + outName);
    }

    public void outerNoStaticMethod(){
        System.out.println("outerNoStaticMethod" + outName + outAge);
    }

    /**
     * 实例内部类的静态属性必须final修饰
     * 实例内部类没有静态代码块和静态方法
     */
    class ExampleInner{
        private static final String innerName = "张三";
        private Integer innerAge = 18;
        private Integer age = 10000;

        public ExampleInner(Integer innerAge) {
            this.innerAge = innerAge;
        }

        public ExampleInner(Integer innerAge, Integer age) {
            this.innerAge = innerAge;
            this.age = age;
        }

        {
            System.out.println("测试实例内部类非静态代码块");
        }

        public ExampleInner() {

        }


        public void noStaticMethod(){
            System.out.println("CommonMethod" + innerName);
            System.out.println("CommonMethod" + innerAge);

            System.out.println("CommonMethod" + outName);
            System.out.println("CommonMethod" + ExampleInnerClass.this.outAge);
            outerStaticMethod();
            outerNoStaticMethod();
        }
    }

    public static void main(String[] args) {
        ExampleInnerClass.ExampleInner exampleInner = new ExampleInnerClass().new ExampleInner();
        Integer innerAge = exampleInner.innerAge;
        exampleInner.noStaticMethod();
    }
}
